﻿/// <reference path="jquery-2.1.0.intellisense.js" />
Parse.initialize("bWl9D4Qrxa8ioRsXrZNmMDp0TEOdE6FfXWQslZ2b", "8VV4L5PZyM5hGdwX1y9wATAolbVyNvwz8tuVCQvu");

function register() {
    var user = new Parse.User();
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    var email = document.getElementById('email').value;
    var heroname = document.getElementById('heroname').value;

    user.set("username", username);
    user.set("password", password);
    user.set("email", email);
    user.set("heroname", heroname);

    user.signUp(null, {
        success: function (user)
        {
            $.ajax({
                url: "api/registration/sendemail",
                data: { name: heroname, email: email },
                async: false
            })
            .fail(function ()
            {
                alert("error");
            })
            .done(function ()
            {
                document.getElementById("message").innerHTML = '<div class="modal-dialog modal-sm"><div class="modal-content"><h1>Registration Successful!!</h1><hr />Activation email sent. If you don\'t receive it in 15 minutes(usually instant) please contact our Board Administrator.<br><button onclick="redirect()" class="btn btn-success">Continue</button></div></div>'
            });
        },
        error: function (user, error) {
             // Show the error message somewhere and let the user try again.
             console.log("Error: " + error.code + " " + error.message);
        }
    });
}
function redirect() {
    location.replace("index.html")
}